import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import static controllers.Events.*;
import controllers.Events;
import controllers.Notifications;
import controllers.Security;
import controllers.Tasks;

import play.test.Fixtures;
import play.test.FunctionalTest;
import play.test.UnitTest;
import models.*;

public class Story15C5testUnit extends UnitTest
{
	
	// to run the test you have to stop the render of JSON opjects 
	@Before
	public void setUp() {
	    Fixtures.deleteAll();
	    Bootstrap.initData();
	}
	@Test
	public void editInTasks()
	{
		User salem = new User("Salem", "sayed", "Abdel Gawad",
				"hhhhh", "123", "hhh@gmail.com", "0101420501",
				"84 bla", "Cairo", "Egypt", "").save();
		Project GUCMafia = new Project(
				"guc",
				20,
				true,
				"This is a joint venture between the GUC and the mafia aiming to kill the life out of GUCians")
				.save();
		
		Component comp = new Component("C1", "User Stories", GUCMafia)
		.save();
		GUCMafia.components.add(comp);
		EventType et1 = new EventType("Meeting").save();
		EventType et2 = new EventType("Sprint").save();
		EventType et4 = new EventType("Default").save();
		TaskType ty = new TaskType("Implementation", true).save();
		TaskStatus st = new TaskStatus("STARTED", true).save();
		TaskStatus st2 = new TaskStatus("End", true).save();
		Task task1=new Task("Destory GUC","Very high", ty, st, null, salem).save();
		Task task2=new Task("Destory AUC","Very high", ty, st, null, salem).save();
		Task task3=new Task("Make Tanta the capital of Egypt :D","Very high", ty, st, null, salem).save();
		Task task4=new Task("Destory C buliding","Very high", ty, st, null, salem).save();
		Task task5=new Task("Destory B building","Very high", ty, st, null, salem).save();
		Task task6=new Task("Make Tanta the capital of the wprld :D","Very high", ty, st, null, salem).save();
		
		
		Event defEvent = new Event("default", et4);
		defEvent.project=GUCMafia;
		defEvent.save();
		
		defEvent.tasks.add(task1);
		defEvent.tasks.add(task2);
		defEvent.tasks.add(task3);
		defEvent.tasks.add(task4);
		defEvent.tasks.add(task5);
		defEvent.tasks.add(task6);
		defEvent.save();
		task1.events.add(defEvent);
		task2.events.add(defEvent);
		task3.events.add(defEvent);
		task4.events.add(defEvent);
		task5.events.add(defEvent);
		task6.events.add(defEvent);
		
		Event event = new Event();
		event.project = GUCMafia;
		event.status = true;
		event.type = et1;
		event.save();
		task5.save();
		task6.save();
		
		Security.authentify("salemsayed", "123");
		
		task1.priority="high";
		assertEquals("high", task1.priority);
		
		
		Tasks.editTaskDescription(""+(Long)task1.getEntityId(), "MHMGAD gamed isa");
		assertEquals("MHMGAD gamed isa", task1.description);
		
		
		Tasks.editTaskDescription(""+(Long)task2.getEntityId(), "");
		assertEquals("Destory AUC", task2.description);
		
		Tasks.changeTaskStatus(((Long)task2.getEntityId()).longValue(), st2.id);
		assertEquals(st2.status, task2.status.status);
		
		
		
			}
}
